// import {
// 	v4 as uuidv4
// } from 'uuid';
// import store from '@/store/index.js';

import LC from "/LC";

// #ifdef APP-PLUS
const mqModule = uni.requireNativePlugin("MeiQia-ChatPlugin");
// #endif

// 美洽客服游客使用
// const kfClientId = uuidv4();

export function kf(id) {
	
// #ifdef H5
(function(a, b, c, d, e, j, s) {
		a[d] = a[d] || function() {
			(a[d].a = a[d].a || []).push(arguments)
		};
		j = b.createElement(c),
			s = b.getElementsByTagName(c)[0];
		j.async = true;
		j.charset = 'UTF-8';
		j.src = 'https://static.meiqia.com/widget/loader.js';
		s.parentNode.insertBefore(j, s);
	})(window, document, 'script', '_MEIQIA');
	_MEIQIA('entId', id);
	_MEIQIA('withoutBtn');
	 _MEIQIA('language', uni.getStorageSync('lang')||'ko')
// #endif
// #ifdef APP-PLUS
  // mqModule.initChatViewManger();
// #endif

	
	// _MEIQIA('language', 'en');
}

export function openkf() {

 // #ifdef H5
 let userinfo=LC.$store('user').info
 if (userinfo.id) {
 
 	_MEIQIA("metadata", {
 		name: userinfo.realname,
 		tel: userinfo.username,
	
		daili:userinfo.agent_name+","+`(${userinfo.agent_code})`
		
 	});
 
 	_MEIQIA('clientId', );
 } else {
 	_MEIQIA("metadata", {
 		name: '游客',
 		contact: '游客',
 		comment: '游客',
 	});
 
 	// _MEIQIA('clientId', kfClientId);
 }
 
 
 _MEIQIA('showPanel');
 
 // #endif
 // #ifdef APP-PLUS
 
 if (userinfo) {
 
 	 mqModule.setClientInfo({
 	    clientInfo:{
 	       name: userinfo.nickname,
 	       comment: userinfo.id,
 	        },
 	    override: true});
 } else {
	 mqModule.setClientInfo({
	    clientInfo:{
	       name: '游客',
	       comment: '游客',
	        },
	    override: true});
 	
 }
mqModule.showMeiQiaChatView();
 // #endif
	
}
